package com.gen.controller;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.gen.entity.Student;
import com.gen.entity.User_course;
import com.gen.service.IUser_courseService;

@Controller
public class User_courseController {
	@Autowired
	private IUser_courseService user_courseService;

	public IUser_courseService getiUser_courseService() {
		return user_courseService;
	}

	public void setiUser_courseService(IUser_courseService user_courseService) {
		this.user_courseService = user_courseService;
	}
	@RequestMapping("/selectAllCourseStudents.do")
	public ModelAndView selectAllCourseStudents() {
		ModelAndView modelAndView = new ModelAndView();
		;List<User_course> user_courses = user_courseService.selectAllCourseStudents();
		modelAndView.addObject("user_courses", user_courses);
		modelAndView.setViewName("listUser_course");
		return modelAndView;
	}
	@RequestMapping("/selectCourseStuentsByCourseId.do")
	public ModelAndView selectCourseStuentsByCourseId(String courseid) {
		ModelAndView modelAndView = new ModelAndView();
		User_course user_course = user_courseService.selectCourseStuentsByCourseId(courseid);
		modelAndView.addObject("user_course", user_course);
		modelAndView.setViewName("detailUser_course");
		return modelAndView;
	}
	@RequestMapping("/selectCourseStuentsByDepartid.do")
	public ModelAndView selectCourseStuentsByDepartid(Integer departid) {
		ModelAndView modelAndView = new ModelAndView();
		List<User_course> user_courses = user_courseService.selectCourseStuentsByDepartid(departid);
		modelAndView.addObject("user_courses", user_courses);
		modelAndView.setViewName("listUser_course");		
		return modelAndView;
	}
	@RequestMapping("/deleteCourseStudent.do")
	public ModelAndView deleteCourseStudent(@Param("courseid") String courseid,@Param("uid") Integer uid) {
		ModelAndView modelAndView = new ModelAndView();
		HashMap<Object, Object> map = new HashMap<Object, Object>();
		map.put("uid", uid);
		map.put("courseid", courseid);
		user_courseService.deleteCourseStudent(map);
		modelAndView.setViewName("detailUser_course");
		return modelAndView;
	}
	@RequestMapping("/addCourseStudent.do")
	public ModelAndView addCourseStudent(@Param("courseid") String courseid,@Param("uid")Integer uid) {
		ModelAndView modelAndView = new ModelAndView();
		HashMap<Object, Object> map = new HashMap<Object, Object>();
		map.put("uid", uid);
		map.put("courseid", courseid);
		user_courseService.addCourseStudent(map);
		modelAndView.setViewName("detailUser_course");
		return modelAndView;
	}
	@RequestMapping("/getStudentsByCourseid.do")
	@ResponseBody
	public Object getStudentsByCourseid(@Param("courseid") String courseid){
		List<Student> list = new LinkedList<Student>();
		list=user_courseService.getStudentsByCourseid(courseid);
//		System.out.println(courseid+list);
		return list;
	}
	@RequestMapping("/getNoCourseStudents.do")
	@ResponseBody
	public Object getNoCourseStudents(@Param("courseid") String courseid) {
		List<Student> list = new LinkedList<Student>();
		list = user_courseService.getNoCourseStudents(courseid);
		return list;
	}
	
}
